package com.sinoglobal.shakeprize.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sinoglobal.shakeprize.R;
import com.sinoglobal.shakeprize.bean.PrizeListParamerItem;
import com.sinoglobal.shakeprize.utils.Contstent;
import com.sinoglobal.shakeprize.utils.FuzzyDateTimeFormatter;
import com.squareup.picasso.Picasso;

/**
 * @author temulu
 * @createdate 2015-8-26下午4:32:02
 * @Description 奖品列表的adapter
 */
public class PrizeListAdapter extends BaseAdapter {
	private Context context;
	private List<PrizeListParamerItem> data;
	private boolean showPrizeMineListItemExpire=false;

	public PrizeListAdapter(Context context, List<PrizeListParamerItem> data) {
		super();
		this.context = context;
		this.data = data;
	}

	public PrizeListAdapter(Context context) {
		super();
		this.context = context;
	}

	public void setData(List<PrizeListParamerItem> data) {
		this.data = data;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.prize_mine_list_item,
					null);
			holder = new ViewHolder();
			holder.prizeMineListItemImg = (ImageView) convertView
					.findViewById(R.id.prizeMineListItemImg);
			holder.prizeMineListItemdes = (TextView) convertView
					.findViewById(R.id.prizeMineListItemdes);
			holder.prizeMineListItemStatus = (TextView) convertView
					.findViewById(R.id.prizeMineListItemStatus);
			holder.prizeMineListItemExpired = (TextView) convertView
					.findViewById(R.id.prizeMineListItemExpired);
			holder.prizeMineListItemExpire = (TextView) convertView
					.findViewById(R.id.prizeMineListItemExpire);
			holder.prizeMineListItemDate = (TextView) convertView
					.findViewById(R.id.prizeMineListItemDate);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Picasso.with(context).load(Contstent.PICTURE_PATH+data.get(position).prizepic).into(holder.prizeMineListItemImg);
		holder.prizeMineListItemdes.setText("获得"+data.get(position).name);
		// 奖品状态：1 积分 已领取(终结状态) ,2 实物 未领取 .3 实物 已过期(终结状态) ,4 实物 待发货, 5 实物 已发货 ,6
		// 实物 完成(终结状态) 7, 实物 自提 8,积分 未发放
		String status = "";
		holder.prizeMineListItemExpired.setVisibility(View.INVISIBLE);
		switch (data.get(position).pickstatus) {
		case 1:
			status="已领取";
			break;
		case 2:
			status="未领取";
			break;
		case 3:
			status="已过期";
			holder.prizeMineListItemExpired.setVisibility(View.VISIBLE);
			break;
		case 4:
			status="待发货";
			break;
		case 5:
			status="已发货";
			break;
		case 6:
			status="完成";
			break;
		case 7:
			status="自提";
			break;
		case 8:
			status="未发放";
			break;
		}
		holder.prizeMineListItemStatus.setText(status);
		holder.prizeMineListItemDate.setText(FuzzyDateTimeFormatter.getTimeAgo(
				context, data.get(position).createDate));
		if (showPrizeMineListItemExpire) {
			holder.prizeMineListItemExpire.setVisibility(View.VISIBLE);
		}
		
		return convertView;
	}

	public void setShowPrizeMineListItemExpire(boolean showPrizeMineListItemExpire) {
		this.showPrizeMineListItemExpire = showPrizeMineListItemExpire;
	}
	
	static class ViewHolder {
		ImageView prizeMineListItemImg;
		TextView prizeMineListItemdes;
		TextView prizeMineListItemStatus;
		TextView prizeMineListItemExpired;
		TextView prizeMineListItemExpire;
		TextView prizeMineListItemDate;
	}

}
